﻿using UnityEngine;

public class OrderItem : MonoBehaviour
{
    public OrderType mType;
    [HideInInspector]
    public Transform mTran;
    [HideInInspector]
    public Renderer mRender;
    [HideInInspector]
    public int mOrder;

    void Start()
    {
        mTran = transform;
        mRender = mTran.GetComponent<Renderer>();
    }

    void LateUpdate()
    {
        int order = (int)(-mTran.position.y * 100);
        if (mOrder != order)
        {
            mOrder = order;
            switch (mType)
            {
                case OrderType.Static:
                    mRender.sortingOrder = mOrder;
                    enabled = false;
                    break;
                case OrderType.Dynamic:
                    mRender.sortingOrder = mOrder;
                    break;
            }
        }
    }
}

public enum OrderType
{
    Static,
    Dynamic,
}
